package thread.thread;

import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.record.common.FutureRecord;
import org.apache.poi.ss.formula.functions.T;
import org.junit.Test;

import javax.security.auth.callback.Callback;
import java.util.concurrent.*;

@Slf4j
public class ThreadInterruptDemo {

    @Test
    public void test1(){
    Thread thread = new Thread(new Runnable() {
      @Override
      public void run() {
        while (true) {

          try {
            TimeUnit.SECONDS.sleep(5);
          } catch (InterruptedException e) {
            e.printStackTrace();
//            Thread.currentThread().interrupt();
          }

          //
          Thread thread1 = Thread.currentThread();
          boolean interrupted = thread1.isInterrupted();
          boolean alive = thread1.isAlive();
          System.out.println(System.currentTimeMillis() + " interrupted：" + interrupted + " isAlive: " + alive);

          if (interrupted) break;

        }
      }
    });

    thread.start();

    //终止方法
    thread.interrupt();


  }

}
